package com.kfm.loginIp.util;

/**
 * @author Aurora雪
 */

import java.util.HashMap;
import java.util.Map;

/**
 * 密钥库,单例
 */
public class KeyStore {
    private static KeyStore instance;
    private final Map<String, String> keyPairs = new HashMap<>();

    private KeyStore() {
        // 初始化时生成密钥对并存储
        Map<Integer, String> genKeyPair = RSAUtil.genKeyPair();
        String publicKey = genKeyPair.get(0);
        String privateKey = genKeyPair.get(1);
        keyPairs.put("publicKey", publicKey);
        keyPairs.put("privateKey", privateKey);
    }

    public static KeyStore getInstance() {
        if (instance == null) {
            instance = new KeyStore();
        }
        return instance;
    }

    public String getPublicKey() {
        return keyPairs.get("publicKey");
    }

    public String getPrivateKey() {
        return keyPairs.get("privateKey");
    }
}
